<template>
  <div class="x-unit" @click.self="closeMask" :style="{ height: `${deviceH}px` }">
    <div class="unit-ctx" :style="{ 'background-image': `url(${modelBg})` }">
      <div class="ctx-title">重点人员</div>
      <div class="ctx-info" v-if="!danganshow">
        <div class="info-type">
          <div class="type-title" style="cursor: pointer;" @click="slecttype()">重点人员总数-{{ alltotal }}</div>
          <ul class="type-list">
            <li
              v-for="item in LotTypeEchartsData"
              :key="item.name"
              class="type-list-rs"
              @click="slecttype(item.name)"
              v-if="item.value>0"
              style="cursor: pointer;"
            >
              <div class="rs-name">
                <span class="name">{{ item.name }}</span>
                <span class="number">{{ item.value }}</span>
              </div>
              <div class="rs-process">
                <div class="process" :style="{ width: `${(item.value / alltotal) * 100}%` }"></div>
              </div>
            </li>
          </ul>
        </div>
        <div class="info-table">
          <div class="table-rs">
            <!-- <div class="table-header">
              <div class="header-select">
                <x-select
                  @selectItem="selectItem"
                  :name="unitTypeName || '人员类型'"
                  :listItem="unitTypeList"
                />
              </div>
              <div class="header-btn" @click="searchEvent">搜索</div>
            </div> -->
            <ul class="table-list">
              <li class="list-item">
                <div class="item-no">序号</div>
                <div class="item-name">姓名</div>
                <div class="item-post">类型</div>
                <div class="item-phone">身份证号码</div>
                <div class="item-state">地址</div>
              </li>
              <li v-for="item,i in LotPageEchartsData" :key="item.id" class="list-item">
                <div class="item-no">{{i+1+pageSize*(pageNum-1)}}</div>
                <div class="item-name">{{ item.name }}</div>
                <div class="item-post">{{ item.type }}</div>
                <div class="item-phone" @click="changedangan(item.idNum)" style="cursor:pointer;">{{ new String().hideidCard(item.idNum) }}</div>
                <div class="item-state" :title="item.address">{{ item.address }}</div>
              </li>
            </ul>
          </div>
          <div v-if="allpage > 0" class="table-footer">
            <x-page
            :currentPage="pageNum"
              @currentChange="currentChange"
              :page-size="5"
              :allpage="allpage"
              :total-num="false"
            />
          </div>
        </div>
      </div>
      <div v-if="danganshow">
         <x-dangan
          :id="danganid"
          v-if="dangan"
          @changedangan="changedangan"
        ></x-dangan>
      </div>
    </div>
  </div>
</template>
<script>
import {
  GetSecurityTotleAndType,
  GetSecurityInfoForPage,
  GetDevSens,
  GetKeyPerson,
  GetDictDataEnum,
  // GetDevSensorForPage,
  GetKeyPersonPageInfo
} from "@/api/peopleApi";
import XPage from "@/components/xpage";
import XSelect from "@/components/xselect";
import XDangan from "@/components/xdanganmodel";
export default {
  name: "xlotmodel",
  props: {
    id: {
      type: String,
      default: ""
    },
    code: {
      type: String,
      default: ""
    }
  },
  computed: {},
  data() {
    return {
      modelBg: require("@/assets/images/modelBg.png"),
      deviceH: 0,
      pageSize: 12,
      pageNum: 1,
      unitTypeList: [],
      LotTypeEchartsData: [],
      LotPageEchartsData: [],
      unitTypeName: "",
      unitType: "",
      total: 0,
      allpage: 0,
      alltotal: 0,
      danganshow:false,
      danganid:'',
      dangan: false,
    };
  },
  components: {
    XPage,
    XSelect,
    XDangan
  },
  beforeMount() {
    let h = document.documentElement.clientHeight || document.body.clientHeight;
    this.deviceH = h;
  },
  mounted() {
    this.GetSecurityData();
    this.GetDictDataEnumList();
  },
  methods: {
    changedangan(id){
      this.dangan = !this.dangan;
      this.danganid = id;
      this.danganshow = !this.danganshow;
    },
    async GetSecurityData() {
      try {
        let camerquery = {
          code: this.code,
          id: this.id
        };
        let pagequery = {
          code: this.code,
          id: this.id,
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          type: this.unitType
        };

        this.LotTypeEchartsData = await GetKeyPerson(camerquery);
        console.log(this.LotTypeEchartsData);
        const res = await GetKeyPersonPageInfo(pagequery);
        if (this.unitType == "") {
          this.alltotal = res.data.total;
        }
        this.total = res.data.total;
        this.LotPageEchartsData = res.data.list;
        console.log(res);
        this.allpage = Math.ceil(this.total / this.pageSize);
      } catch (error) {
        this.$message({
          type: "error",
          message: error
        });
      }
    },
    //关闭
    closeMask() {
      this.$emit("closeMask");
    },
    //获取类型
    async GetDictDataEnumList() {
      try {
        const res = await GetDictDataEnum("key_personnel");
        res.unshift({
          enumName: "全部",
          id: ""
        });
        this.unitTypeList = res;
      } catch (error) {
        this.$message({
          type: "error",
          message: error
        });
      }
    },
    //分页
    currentChange(n) {
      this.pageNum = n;
      this.GetSecurityData();
    },
    //搜索
    searchEvent() {
      this.GetSecurityData();
    },
    selectItem(name, id) {
      this.unitTypeName = name;
      this.unitType = id;
    },
    slecttype(name) {
      if(name){
        this.unitTypeName = name;
        this.unitTypeList.map(item=>{
          if(item.enumName==name){
            this.unitType=item.id
            this.GetSecurityData();
          }
        })
      }else{
        //全部
        this.unitTypeName = '';
        this.unitType=''
        this.GetSecurityData();
      }

    }
  }
};
</script>
<style lang="less" scoped>
.x-unit {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  .item-no {
    width: 50px;
    height: 100%;
    font-family: PingFangSC-Regular;
    font-size: 14px;
    color: #ffffff;
    line-height: 36px;
    text-align: center;
  }
  .unit-ctx {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 1177px;
    height: 800px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;
    padding: 10px 30px;
    box-sizing: border-box;
    .ctx-title {
      width: 100%;
      padding-top: 10px;
      box-sizing: border-box;
      font-family: PingFangSC-Medium;
      font-size: 24px;
      color: #e9e9e9;
      letter-spacing: 4.8px;
      text-align: center;
      box-sizing: border-box;
    }
    .ctx-info {
      width: 100%;

      height: 748px;
      padding-top: 20px;
      box-sizing: border-box;
      display: flex;
      justify-content: space-around;
      align-items: flex-start;
      .info-type {
        flex: 1;
        .type-title {
          width: 100%;
          font-family: PingFangSC-Medium;
          font-size: 18px;
          color: #69d3da;
          letter-spacing: 0;
          text-align: left;
          line-height: 36px;
        }
        .type-list {
          width: 100%;
          padding: 0;
          margin-top: 26px;
          list-style: none;
          display: flex;
          flex-direction: column;
          justify-content: flex-start;
          box-sizing: border-box;
          .type-list-rs {
            width: 100%;
            list-style: none;
            margin-bottom: 20px;
            .rs-name {
              width: 100%;
              display: flex;
              justify-content: space-around;
              align-items: center;
              font-family: PingFangSC-Regular;
              font-size: 12px;
              color: #e5e5e5;
              margin-bottom: 5px;
              .name {
                flex: 2;
                text-align: left;
              }
              .number {
                flex: 1;
                text-align: right;
              }
            }
            .rs-process {
              width: 100%;
              height: 6px;
              border-radius: 4px;
              background: #333333;
              .process {
                transition: width 0.3s ease-in-out;
                height: 100%;
                border-radius: 4px;
                background-image: linear-gradient(
                  270deg,
                  #68e0cf 0%,
                  #209cff 100%
                );
              }
            }
          }
        }
      }
      .info-table {
        flex: 3;
        height: 659px;
        padding-left: 40px;
        box-sizing: border-box;
        .table-rs {
          width: 100%;
          height: 562px;
          overflow-y: auto;

          .table-header {
            width: 100%;
            height: 36px;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            position: relative;
            .header-item {
              width: 186px;
              height: 100%;
              border: none;
              outline: none;
              background: #06121d;
              border: 1px solid rgba(62, 178, 215, 0);
              border-radius: 4px;
              font-size: 14px;
              color: #fff;
              padding: 0 14px;
              box-sizing: border-box;
              .input {
                font-size: 14px;
                color: #fff;
                width: 100%;
                height: 100%;
                border: none;
                outline: none;
                background: transparent;
              }
            }
            .header-select {
              width: 186px;
              margin-right: 20px;
              height: 100%;
              background: #06121d;
              border: 1px solid rgba(62, 178, 215, 0);
              border-radius: 4px;
              font-size: 14px;
              color: #fff;
              padding: 0 14px;
              box-sizing: border-box;
              display: flex;
              justify-content: space-between;
              align-items: center;
              .select-name {
                width: calc(100% - 20px);
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                word-break: normal;
                text-align: left;
              }
              .iconfont {
                width: 20px;
                text-align: right;
                font-size: 14px;
                color: #fff;
                font-weight: 600;
              }
            }
            .header-more {
              width: 56px;
              margin-left: 20px;
              font-family: PingFangSC-Regular;
              font-size: 14px;
              color: #72edf5;
              line-height: 28px;
              text-decoration: underline;
            }
            .header-btn {
              position: absolute;
              top: 50%;
              transform: translateY(-50%);
              right: 0;
              width: 66px;
              height: 100%;
              background: #72edf5;
              border-radius: 4px;
              text-align: center;
              line-height: 36px;
              font-family: PingFangSC-Regular;
              font-size: 14px;
              color: #000000;
            }
          }
          .table-list {
            width: 100%;
            list-style: none;
            padding: 0;
            margin-top: 15px;
            .list-item {
              padding: 0;
              margin: 0;
              list-style: none;
              width: 100%;
              display: flex;
              justify-content: space-between;
              align-items: center;
              height: 36px;
              &:nth-of-type(2n + 1) {
                background: #06121d;
              }
              &:nth-of-type(2n) {
                background: transparent;
              }
              .item-name {
                width: 94px;
                padding-left: 33px;
                box-sizing: border-box;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
                text-align: left;
              }
              .item-post {
                width: 150px;
                // padding-left: 33px;
                box-sizing: border-box;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
                text-align: left;
              }
              .item-phone {
                width: 253px;
                // padding-left: 33px;
                box-sizing: border-box;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
                text-align: left;
              }
              .item-state {
                width: 300px;
                // padding-left: 33px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                box-sizing: border-box;
                height: 100%;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #ffffff;
                line-height: 36px;
                text-emphasis: none;
                text-align: left;
              }
            }
          }
        }
        .table-footer {
          width: 100%;
          padding-top: 60px;
          box-sizing: border-box;
          display: flex;
          justify-content: flex-end;
        }
      }
    }
  }
}
</style>
